﻿using System;
using System.Windows.Forms;
using System.IO;

namespace 读取文件夹下的txt文档
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public string str;
        System.Collections.ArrayList ar = new System.Collections.ArrayList();
        System.Collections.ArrayList br = new System.Collections.ArrayList();
        public string str1;
        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            string path = dialog.SelectedPath;
            if (dialog.ShowDialog()==DialogResult.OK)
            {
                DirectoryInfo dic = new DirectoryInfo(@"dialog.SelectedPath");
                foreach (FileInfo fi in dic.GetFiles(path)) 
                {
                    if(fi.Extension==".txt")
                {
                    System.IO.StreamReader sr = new System.IO.StreamReader(fi.FullName, System.Text.Encoding.GetEncoding("gb2312"));
                    string content=sr.ReadToEnd();
                    while(sr.Peek()>=0)
                    {
                        ar.Add(content);
                    }
                        sr.Close();sr.Dispose();
                }
                    for (int a = 0; a < ar.Count; a++)
                    {
                        str = ar[a].ToString();
                    }
                    textBox1.Text = str; 
                    

                }
                
            }
            

        }

       
    }
}
